# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=open-iscsi
pkgver=2.1.9
pkgrel=1
pkgdesc="High performance, transport independent, multi-platform iSCSI initiator"
url="https://www.open-iscsi.com"
arch="all"
license="GPL-2.0-only"
makedepends="kmod-dev libmount linux-headers openssl-dev>3
	open-isns-dev util-linux-dev meson bash perl"
options="!check"
subpackages="$pkgname-dev $pkgname-libs $pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/open-iscsi/open-iscsi/archive/$pkgver.tar.gz
	iscsid.initd
	iscsid.confd
	iscsid.conf
	bash.patch
	musl-fixes.patch
	add-missing-headers.patch
	dont-use-lib64.patch
	remove-werror.patch
	"

build() {
	# musl doesn't have glob_onlydir but by spec it's also not guaranteed to return only dirs anyway
	CFLAGS="$CFLAGS -DGLOB_ONLYDIR=0" \
	abuild-meson \
		-Db_lto=true \
		-Dno_systemd=true \
		-Drulesdir="/usr/lib/udev/rules.d" \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	install -Dm755 "$srcdir"/iscsid.initd "$pkgdir"/etc/init.d/iscsid
	install -Dm644 "$srcdir"/iscsid.confd "$pkgdir"/etc/conf.d/iscsid
	install -Dm644 "$srcdir"/iscsid.conf "$pkgdir"/etc/iscsi/iscsid.conf
}

sha512sums="
25c28da5918b775ca54d3e55591eca0b4f7b5be33d803cad28fce1e9b2334b43cee1423a4e1819497b322e0f420dcd8d74226f442ca432233d1753565b11a5bb  open-iscsi-2.1.9.tar.gz
52e273d20d3c95c943409d3b6251f0447e19a822d32ff33d3c8dc1e9b8c6065ab72b823fe9cb72f5d92256d3a219417a3847dc59815d29f727fc59c4e49716a8  iscsid.initd
3ba1825ee8b39ce2c58d70b59d6c2d6a954a8c65ce9adf920fb44d046cfe0f7f54bcc70f3f3c24754f0e866abdc92b4a1716fb516c45278b217532b97a6d948a  iscsid.confd
4cc7c1923047616d908806aab96d468cb7b99ff9f8a9e02a039866b66db4ae856bd9f414854712d8a57c21614674f4468736bce26a4199c2ff054a165bca26e0  iscsid.conf
89e44837a1d7fcd3b7de88ae7f25a3c2d3ff24cf01bbe752882e56d25e9ee41ef57dac9d21257057b9a4fcd6fe18650b7f4926f934d348fdb6080e6b42e43ac1  bash.patch
1b89ffd6de0dc7bb63fc2702a97e49df4369158c66ee609acfc041b1677c07fbd964b7a709f1f324fa51a9842d4d3e11611d9783e18d526372d468163c0ac8db  musl-fixes.patch
104b559eb368459a7151657fbca63927b6b1032bda272e903a1633c8b9d3ed199f2c5cca0e6741bcd5fa6e860d1ff2d111caf58d60d9f0a736ad767e8ae0427b  add-missing-headers.patch
86a9c4be4abd34821f156f9df586c530dc2b0efc96e961cb15fd22846856cc1e76aae85806e8d0eb9f3d3e3acd7f73fe8d2a1de8944903b503e256e6a99bb2dd  dont-use-lib64.patch
d99ef789d1aab1e7ba81e3f2b334a9518f1174cd53b4600bfd7e866973cdfa87664b2161c994ae7c35526a7d9165e0e2b3036f7dacc139b90fa3d0a90b6f6599  remove-werror.patch
"
